home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_lib1 / rkrm_lib1.lha / Intuition / Boopsi / userkmmodel.c < prev   
C/C++ Source or Header  |  1992-09-03  |  12KB  |  343 lines

  1. ;/* UseRKMModel.c - Execute me to compile me with Lattice 5.10b
  2. LC -b1 -cfistq -v -y -j73 UseRKMModel.c
  3. Blink FROM LIB:c.o,UseRKMModel.o TO UseRKMModel LIBRARY LIB:LC.lib,LIB:Amiga.lib,RKMModel.o
  4. quit
  5. */
  6.  
  7. /*
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33.  
  34. #include <exec/types.h>
  35. #include <intuition/intuition.h>
  36. #include <intuition/classusr.h>
  37. #include <intuition/imageclass.h>
  38. #include <intuition/gadgetclass.h>
  39. #include <intuition/classes.h>
  40. #include <intuition/icclass.h>
  41. #include <clib/exec_protos.h>
  42. #include <clib/intuition_protos.h>
  43. #include <clib/alib_protos.h>
  44. #include <clib/dos_protos.h>
  45. #include <stdio.h>
  46.  
  47. #include "RKMModel.h"
  48.  
  49. #ifdef LATTICE
  50. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  51. int chkabort(void) { return(0); }
  52. #endif
  53.  
  54. #define PROPID              1L
  55. #define INTEGERID           2L
  56. #define RIGHTID             3L
  57. #define LEFTID              4L
  58. #define PROPWIDTH           80L
  59. #define PROPHEIGHT          10L
  60. #define INTWIDTH            50L
  61. #define INTHEIGHT           14L
  62. #define VISIBLE             10L
  63. #define TOTAL               100L
  64. #define INITIALVAL          25L
  65. #define MINWINDOWWIDTH      80
  66. #define MINWINDOWHEIGHT     (PROPGADGETHEIGHT + 70)
  67. #define MAXCHARS            4L
  68.  
  69. UBYTE *vers = "\0$VER: UseRKMModel 37.1";
  70.  
  71. BOOL MakeGadgetsAndRKMModel(void);
  72.  
  73.  
  74.  
  75. struct TagItem go2rkmmodel[] = {
  76.     {PGA_Top, RKMMOD_CurrVal},
  77.     {STRINGA_LongVal, RKMMOD_CurrVal},
  78.     {TAG_END,}
  79. };
  80.  
  81. struct TagItem right2rkmmodel[] = {
  82.     {GA_ID, RKMMOD_Up},
  83.     {TAG_END,}
  84. };
  85.  
  86. struct TagItem left2rkmmodel[] = {
  87.     {GA_ID, RKMMOD_Down},
  88.     {TAG_END,}
  89. };
  90.  
  91. struct TagItem mapcurrval2prop[] = {
  92.     {RKMMOD_CurrVal, PGA_Top},
  93.     {TAG_END,}
  94. };
  95.  
  96. struct TagItem mapcurrval2int[] = {
  97.     {RKMMOD_CurrVal, STRINGA_LongVal},
  98.     {TAG_END,}
  99. };
  100.  
  101.  
  102.  
  103. struct Library *IntuitionBase, *UtilityBase;
  104. struct Window *w;
  105. struct DrawInfo *mydrawinfo;
  106.  
  107. Class *rkmmodcl;
  108. Object *rkmmodel, *currval2int, *currval2prop;
  109. struct Gadget *prop, *integer, *leftbut, *rightbut;
  110. struct Image *rightimage, *leftimage;
  111.  
  112. struct IntuiMessage *msg;
  113.  
  114. void main(void)
  115. {
  116.     BOOL done = FALSE;
  117.         ULONG qwe;
  118.  
  119.  
  120.     if (IntuitionBase = OpenLibrary("intuition.library", 37L))
  121.     {
  122.         if (UtilityBase = OpenLibrary("utility.library", 37L))
  123.         {
  124.             if (w = OpenWindowTags(NULL,
  125.                 WA_Flags,       WFLG_DEPTHGADGET | WFLG_DRAGBAR |
  126.                                     WFLG_CLOSEGADGET | WFLG_SIZEGADGET,
  127.                 WA_IDCMP,       IDCMP_CLOSEWINDOW,
  128.                 TAG_END))
  129.             {
  130.                 if (rkmmodcl = initRKMModClass())
  131.                 {
  132.                     if (mydrawinfo = GetScreenDrawInfo(w->WScreen))
  133.                     {
  134.                         if (MakeGadgetsAndRKMModel())
  135.                         {
  136.                             DoMethod(rkmmodel, OM_ADDMEMBER, currval2prop);
  137.                             DoMethod(rkmmodel, OM_ADDMEMBER, currval2int);
  138.  
  139.                             WindowLimits(w,(LONG)(w->BorderLeft + w->BorderRight)
  140.                                     + integer->LeftEdge + integer->Width + 10L,
  141.                                 (LONG)(w->BorderTop + w->BorderBottom)
  142.                                     + prop->Height+10L,
  143.                                 w->MaxWidth,
  144.                                 w->MaxHeight);
  145.  
  146.                             AddGList(w, prop, -1, -1, NULL);
  147.                             RefreshGadgets(prop, w, NULL);
  148.  
  149.         GetAttr(RKMMOD_CurrVal, rkmmodel, &qwe);
  150.         printf("RKMMOD_CurrVal = %ld\n", qwe);
  151.         Delay(200);
  152.  
  153.         if (SetAttrs(rkmmodel, RKMMOD_CurrVal, 10L, TAG_DONE))
  154.         {
  155.                 RefreshGadgets(prop, w, NULL);
  156.         }
  157.         GetAttr(RKMMOD_CurrVal, rkmmodel, &qwe);
  158.         printf("RKMMOD_CurrVal = %ld\n", qwe);
  159.         Delay(200);
  160.  
  161.         if (SetAttrs(rkmmodel, RKMMOD_CurrVal, 30L, TAG_DONE))
  162.         {
  163.                 RefreshGadgets(prop, w, NULL);
  164.         }
  165.         GetAttr(RKMMOD_CurrVal, rkmmodel, &qwe);
  166.         printf("RKMMOD_CurrVal = %ld\n", qwe);
  167.         Delay(200);
  168.  
  169.         if (SetAttrs(rkmmodel, RKMMOD_CurrVal, 50L, TAG_DONE))
  170.         {
  171.                 RefreshGadgets(prop, w, NULL);
  172.         }
  173.         GetAttr(RKMMOD_CurrVal, rkmmodel, &qwe);
  174.         printf("RKMMOD_CurrVal = %ld\n", qwe);
  175.         Delay(200);
  176.  
  177.         if (SetAttrs(rkmmodel, RKMMOD_Up, 1L, TAG_DONE))
  178.         {
  179.                 RefreshGadgets(prop, w, NULL);
  180.         }
  181.  
  182.  
  183.                             /* Wait for the user to click window close gadget. */
  184.                             while (done == FALSE)
  185.                             {
  186.                                 WaitPort((struct MsgPort *)w->UserPort);
  187.                                 while (msg = (struct IntuiMessage *)
  188.                                    GetMsg((struct MsgPort *)w->UserPort))
  189.                                 {
  190.                                     if (msg->Class == IDCMP_CLOSEWINDOW)
  191.                                     {
  192.                                         done = TRUE;
  193.                                     }
  194.                                     ReplyMsg(msg);
  195.                                 }
  196.                             }
  197.                             RemoveGList(w, prop, -1);
  198.  
  199.                             DisposeObject(rightimage);
  200.                             DisposeObject(leftimage);
  201.                             DisposeObject(rkmmodel);
  202.                             DisposeObject(prop);
  203.                             DisposeObject(integer);
  204.                             DisposeObject(leftbut);
  205.                             DisposeObject(rightbut);
  206.                         }
  207.                         FreeScreenDrawInfo(w->WScreen, mydrawinfo);
  208.                     }
  209.                     freeRKMModClass(rkmmodcl);
  210.                 }
  211.                 CloseWindow(w);
  212.             }
  213.             CloseLibrary(UtilityBase);
  214.         }
  215.         CloseLibrary(IntuitionBase);
  216.     }
  217. }
  218.  
  219.  
  220.  
  221. BOOL MakeGadgetsAndRKMModel(void)
  222. {
  223.     WORD x = 9;
  224.  
  225.     if (rightimage = (struct Image *)NewObject(NULL, "sysiclass",
  226.         SYSIA_Which,    RIGHTIMAGE,
  227.         SYSIA_DrawInfo, mydrawinfo,
  228.         TAG_END))
  229.     {
  230.         x--;
  231.         if (leftimage = (struct Image *)NewObject(NULL, "sysiclass",
  232.             SYSIA_Which,    LEFTIMAGE,
  233.             SYSIA_DrawInfo, mydrawinfo,
  234.             TAG_END))
  235.         {
  236.             x--;
  237.             if (rkmmodel = NewObject(rkmmodcl, NULL,
  238.                 RKMMOD_CurrVal, INITIALVAL,
  239.                 RKMMOD_Limit,   (TOTAL - VISIBLE),
  240.                 TAG_END))
  241.             {
  242.                 x--;
  243.                 if (prop = (struct Gadget *)NewObject(NULL, "propgclass",
  244.                     GA_ID,          PROPID,
  245.                     GA_Top,         (w->BorderTop) + 5L,
  246.                     GA_Left,        (w->BorderLeft) + 5L,
  247.                     GA_Width,       PROPWIDTH,
  248.                     GA_Height,      PROPHEIGHT,
  249.                     ICA_MAP,        go2rkmmodel,
  250.                     ICA_TARGET,     rkmmodel,
  251.                     PGA_Freedom,    FREEHORIZ,
  252.                     PGA_Total,      TOTAL,
  253.                     PGA_Top,        INITIALVAL,
  254.                     PGA_Visible,    VISIBLE,
  255.                     PGA_NewLook,    TRUE,
  256.                     TAG_END))
  257.  
  258.                 {
  259.                     x--;
  260.                     if (integer = (struct Gadget *)NewObject(NULL, "strgclass",
  261.                         GA_ID,              INTEGERID,
  262.                         GA_Top,             (w->BorderTop) + 5L,
  263.                         GA_Left,            prop->LeftEdge + prop->Width + 48L,
  264.                         GA_Width,           INTWIDTH,
  265.                         GA_Height,          INTHEIGHT,
  266.                         ICA_MAP,            go2rkmmodel,
  267.                         ICA_TARGET,         rkmmodel,
  268.                         GA_Previous,        prop,
  269.                         STRINGA_LongVal,    INITIALVAL,
  270.                         STRINGA_MaxChars,   MAXCHARS,
  271.                         TAG_END))
  272.                     {
  273.                         x--;
  274.                         if (leftbut = (struct Gadget *)NewObject(NULL,
  275.                             "buttongclass",
  276.                             GA_ID,              LEFTID,
  277.                             GA_Image,           leftimage,
  278.                             GA_Top,             (w->BorderTop) +  5L,
  279.                             GA_Left,            prop->LeftEdge + prop->Width,
  280.                             ICA_MAP,            left2rkmmodel,
  281.                             ICA_TARGET,         rkmmodel,
  282.                             GA_Previous,        integer,
  283.                             TAG_END))
  284.                         {
  285.                             x--;
  286.                             if (rightbut = (struct Gadget *)NewObject(NULL,
  287.                                 "buttongclass",
  288.                                 GA_ID,        RIGHTID,
  289.                                 GA_Image,    rightimage,
  290.                                 GA_Top,      (w->BorderTop) +  5L,
  291.                                 GA_Left,     prop->LeftEdge + prop->Width
  292.                                                  + leftbut->Width,
  293.                                 ICA_MAP,     right2rkmmodel,
  294.                                 ICA_TARGET,  rkmmodel,
  295.                                 GA_Previous, leftbut,
  296.                                 TAG_END))
  297.                             {
  298.                                 x--;
  299.                                 if (currval2prop = NewObject(NULL, "icclass",
  300.                                     ICA_MAP,    mapcurrval2prop,
  301.                                     ICA_TARGET, prop,
  302.                                     TAG_END))
  303.                                 {
  304.                                     x--;
  305.                                     if (currval2int = NewObject(NULL, "icclass",
  306.                                         ICA_MAP,    mapcurrval2int,
  307.                                         ICA_TARGET, integer,
  308.                                         TAG_END))
  309.                                     {
  310.                                         x--;
  311.                                     }
  312.                                 }
  313.                             }
  314.                         }
  315.                     }
  316.                 }
  317.             }
  318.         }
  319.     }
  320.     switch (x)
  321.     {
  322.         case 0:
  323.             return((BOOL)TRUE);
  324.         case 1:
  325.             DisposeObject(currval2prop);
  326.         case 2:
  327.             DisposeObject(rightbut);
  328.         case 3:
  329.             DisposeObject(leftbut);
  330.         case 4:
  331.             DisposeObject(integer);
  332.         case 5:
  333.             DisposeObject(prop);
  334.         case 6:
  335.             DisposeObject(rkmmodel);
  336.         case 7:
  337.             DisposeObject(leftimage);
  338.         case 8:
  339.             DisposeObject(rightimage);
  340.     }
  341.     return((BOOL)FALSE);
  342. }
  343.